# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=molequeue
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.0
pkgrel=2
pkgdesc="Desktop integration of high performance computing resources (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://www.openchemistry.org/projects/molequeue/'
msys2_repository_url="https://github.com/OpenChemistry/molequeue"
msys2_references=(
  'archlinux: molequeue'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt5-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/OpenChemistry/molequeue/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-disable-deploy.patch
        002-fix-cmake-config-file.patch)
sha256sums=('7dd234742c8d73be95281fedf4ed9d09648ecc351afb5f098cd32f48c3df3bd5'
            'eb3470a41e764e79d09e62718cfcd24bf5e7ca8193a2ed3da846ce5a6504e7c0'
            '9343b828858e873bd40cb67a3a37a3b1bc4d83cb23264e3e5038c8a6f03cd45a')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-disable-deploy.patch
  patch -p1 -i "${srcdir}"/002-fix-cmake-config-file.patch
}

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe -Wno-dev \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
